import sim

class CoppeliasimClass():
    def __init__(self):
        pass

    def Connect(self, ip='127.0.0.1', port=19997):
        sim.simxFinish(-1)  # Close all opened connections
        # Connect to CoppeliaSim remote API server
        client = sim.simxStart(ip, port, True, True, 5000, 5)
        if client == -1:
            print("Failed connecting to remote API server")
        return client

    def GetHandles(self, client, number, name):
        objecthandle = []
        if number < 2:
            _, objecthandle = sim.simxGetObjectHandle(client, name, sim.simx_opmode_blocking)
            return objecthandle
        else:
            for i in range(number):
                _, Handle = sim.simxGetObjectHandle(client, name + str(i + 1), sim.simx_opmode_blocking)
                objecthandle.append(Handle)
            return objecthandle
   